// pages/lxwomen/lxwomen.js
var app = getApp();
var ea = require('../../utils/each.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    getcampusurl: app.data.url +'/zhongxue/maoapi/getcampus',
    src:app.data.url +"/uploads/zhongxue/xuexiaodizhi.png",

    xiaoqus:[
      {
        name: "成都博知堂教育分校", cishu: "25", date: "2017-06-15", address: "四川省成都市锦江区中纱帽街8号3栋50013栋5001室",
      },
       {
        name: "北京博知堂教育分校", cishu: "25", date: "2018-08-16", address: "北京成都市锦江区中纱帽街8号3栋50013栋5001室",
      }
    
    ],
    campus:[],
    page:1
  },
  
  xqs:function(e){
    var id = e.currentTarget.dataset.id;
   wx.navigateTo({
     url: '/pages/lxwomenxq/lxwomenxq?id='+id
   })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },
  getData:function(){
    var page = this.data.page;
    if(page==0){
      wx.showToast({
        title: '没有更多了',
        icon:'none',
        duration: app.data.quanbushijian
      })
      return
    }
    var that = this;
    var user = wx.getStorageSync('user');
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: that.data.getcampusurl,
      data:{token:user.token,page:page},
      method:'post',
      success:function(res){
        var data = res.data;
        if(data.code==200){
          var shuju = data.data;
          if(shuju.length<10){
            that.setData({page:0})
          }else{
            that.setData({page:page+1})
          }
          var campus = that.data.campus;
          ea.each(shuju,function(i,v){
            campus.push(v);
          })
          console.log(campus);
          that.setData({ campus: campus})

        }else{
          wx.showToast({
            title: data.msg,
            icon:'none',
            duration: app.data.quanbushijian
          })
        }
        wx.hideLoading();
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
   
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      campus: [],
      page: 1
    });
    this.getData();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      path: '/pages/indexfirst/indexfirst',
    }
  }
})